

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/clock.jpg">
  <link rel="icon" href="/img/clock.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="lingllqs">
  <meta name="keywords" content="爱编程的少侠">
  
    <meta name="description" content="x86 汇编语言 寄存器    寄存器 描述     AX 累加结果数据   BX 数据段数据指针   CX 字符串和循环计数器   DX I&#x2F;O指针   DI 目的数据指针   SI 源数据指针   SP 栈指针   BP 栈数据指针     其中可以放单独使用高八位和低八位的寄存器     寄存器 高八位 低八位     AX AH AL   BX BH BL   CX CH CL   DX">
<meta property="og:type" content="article">
<meta property="og:title" content="8086处理器">
<meta property="og:url" content="https://lingllqs.github.io/archives/7d86c998.html">
<meta property="og:site_name" content="少侠的博客">
<meta property="og:description" content="x86 汇编语言 寄存器    寄存器 描述     AX 累加结果数据   BX 数据段数据指针   CX 字符串和循环计数器   DX I&#x2F;O指针   DI 目的数据指针   SI 源数据指针   SP 栈指针   BP 栈数据指针     其中可以放单独使用高八位和低八位的寄存器     寄存器 高八位 低八位     AX AH AL   BX BH BL   CX CH CL   DX">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lingllqs.github.io/img/gdt.jpg">
<meta property="og:image" content="https://lingllqs.github.io/img/GDT.jpg">
<meta property="og:image" content="https://lingllqs.github.io/img/descriptor.jpg">
<meta property="og:image" content="https://lingllqs.github.io/img/ascii-ctl.png">
<meta property="article:published_time" content="2022-12-05T09:17:51.000Z">
<meta property="article:modified_time" content="2023-09-16T15:49:21.980Z">
<meta property="article:author" content="lingllqs">
<meta property="article:tag" content="8086">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://lingllqs.github.io/img/gdt.jpg">
  
  
  
  <title>8086处理器 - 少侠的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"lingllqs.github.io","root":"/","version":"1.9.5","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":"f8764fb24a6f40d929b789fbec8ad09b","google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  

  
    <!-- Baidu Analytics -->
    <script async>
      if (!Fluid.ctx.dnt) {
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?f8764fb24a6f40d929b789fbec8ad09b";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
      }
    </script>
  

  
    <!-- Google tag (gtag.js) -->
    <script async>
      if (!Fluid.ctx.dnt) {
        Fluid.utils.createScript("https://www.googletagmanager.com/gtag/js?id=", function() {
          window.dataLayer = window.dataLayer || [];
          function gtag() {
            dataLayer.push(arguments);
          }
          gtag('js', new Date());
          gtag('config', '');
        });
      }
    </script>
  

  

  

  

  



  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>炸天帮</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/" target="_self">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/" target="_self">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/" target="_self">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/" target="_self">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/" target="_self">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/" target="_self">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" rel="external nofollow noreferrer" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" rel="external nofollow noreferrer" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="8086处理器"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-12-05 17:17" pubdate>
          2022年12月5日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          3.1k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          27 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">8086处理器</h1>
            
            
              <div class="markdown-body">
                
                <h1>x86 汇编语言</h1>
<h2 id="寄存器">寄存器</h2>
<table>
<thead>
<tr>
<th style="text-align:center">寄存器</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">AX</td>
<td>累加结果数据</td>
</tr>
<tr>
<td style="text-align:center">BX</td>
<td>数据段数据指针</td>
</tr>
<tr>
<td style="text-align:center">CX</td>
<td>字符串和循环计数器</td>
</tr>
<tr>
<td style="text-align:center">DX</td>
<td>I/O指针</td>
</tr>
<tr>
<td style="text-align:center">DI</td>
<td>目的数据指针</td>
</tr>
<tr>
<td style="text-align:center">SI</td>
<td>源数据指针</td>
</tr>
<tr>
<td style="text-align:center">SP</td>
<td>栈指针</td>
</tr>
<tr>
<td style="text-align:center">BP</td>
<td>栈数据指针</td>
</tr>
</tbody>
</table>
<ul>
<li>其中可以放单独使用高八位和低八位的寄存器</li>
</ul>
<table>
<thead>
<tr>
<th style="text-align:center">寄存器</th>
<th style="text-align:center">高八位</th>
<th style="text-align:center">低八位</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">AX</td>
<td style="text-align:center">AH</td>
<td style="text-align:center">AL</td>
</tr>
<tr>
<td style="text-align:center">BX</td>
<td style="text-align:center">BH</td>
<td style="text-align:center">BL</td>
</tr>
<tr>
<td style="text-align:center">CX</td>
<td style="text-align:center">CH</td>
<td style="text-align:center">CL</td>
</tr>
<tr>
<td style="text-align:center">DX</td>
<td style="text-align:center">DH</td>
<td style="text-align:center">DL</td>
</tr>
</tbody>
</table>
<h2 id="段寄存器">段寄存器</h2>
<table>
<thead>
<tr>
<th style="text-align:center">段寄存器</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">CS</td>
<td>代码段寄存器</td>
</tr>
<tr>
<td style="text-align:center">DS</td>
<td>数据段寄存器</td>
</tr>
<tr>
<td style="text-align:center">SS</td>
<td>栈段寄存器</td>
</tr>
<tr>
<td style="text-align:center">ES</td>
<td>扩展寄存器</td>
</tr>
</tbody>
</table>
<h2 id="其它寄存器">其它寄存器</h2>
<p>IP：指令指针寄存器<br>
FLAG/PSW：标志寄存器（程序状态字）</p>
<h2 id="标志寄存器FLAG">标志寄存器FLAG</h2>
<table>
<thead>
<tr>
<th style="text-align:center">11</th>
<th style="text-align:center">10</th>
<th style="text-align:center">9</th>
<th style="text-align:center">8</th>
<th style="text-align:center">7</th>
<th style="text-align:center">6</th>
<th style="text-align:center">5</th>
<th style="text-align:center">4</th>
<th style="text-align:center">3</th>
<th style="text-align:center">2</th>
<th style="text-align:center">1</th>
<th style="text-align:center">0</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">OF</td>
<td style="text-align:center">DF</td>
<td style="text-align:center">IF</td>
<td style="text-align:center">TF</td>
<td style="text-align:center">SF</td>
<td style="text-align:center">ZF</td>
<td style="text-align:center"></td>
<td style="text-align:center">AF</td>
<td style="text-align:center"></td>
<td style="text-align:center">PF</td>
<td style="text-align:center"></td>
<td style="text-align:center">CF</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th style="text-align:center">位</th>
<th style="text-align:center">标志</th>
<th>描述</th>
<th>英文全拼</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">0</td>
<td style="text-align:center">CF</td>
<td>进位标志</td>
<td>carry</td>
</tr>
<tr>
<td style="text-align:center">1</td>
<td style="text-align:center"></td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center">2</td>
<td style="text-align:center">PF</td>
<td>奇偶标志</td>
<td>parity</td>
</tr>
<tr>
<td style="text-align:center">3</td>
<td style="text-align:center"></td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center">4</td>
<td style="text-align:center">AF</td>
<td>辅助进位标志</td>
<td>auxiliary</td>
</tr>
<tr>
<td style="text-align:center">5</td>
<td style="text-align:center"></td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center">6</td>
<td style="text-align:center">ZF</td>
<td>零标志</td>
<td>zero</td>
</tr>
<tr>
<td style="text-align:center">7</td>
<td style="text-align:center">SF</td>
<td>符号标志</td>
<td>sign</td>
</tr>
<tr>
<td style="text-align:center">8</td>
<td style="text-align:center">TF</td>
<td>陷阱标志</td>
<td>trap</td>
</tr>
<tr>
<td style="text-align:center">9</td>
<td style="text-align:center">IF</td>
<td>中断允许标志</td>
<td>interrupt</td>
</tr>
<tr>
<td style="text-align:center">10</td>
<td style="text-align:center">DF</td>
<td>方向标志</td>
<td>direction</td>
</tr>
<tr>
<td style="text-align:center">11</td>
<td style="text-align:center">OF</td>
<td>溢出标志</td>
<td>overflow</td>
</tr>
</tbody>
</table>
<h2 id="8086寻址方式">8086寻址方式</h2>
<blockquote>
<p>物理地址 = 段地址 × 16 + 偏移地址</p>
<p>8086CPU有20根地址线，总共可以访问 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mn>2</mn><mn>20</mn></msup><mo>=</mo><mn>1</mn><mi>M</mi></mrow><annotation encoding="application/x-tex">2^{20} = 1M</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8141em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">20</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">1</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span></span></span></span> 的内存<br>
寄存器最大16位，可以表示的最大地址为: <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mn>2</mn><mn>16</mn></msup><mo>=</mo><mn>64</mn><mi>K</mi></mrow><annotation encoding="application/x-tex">2^{16} = 64K</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8141em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">16</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">64</span><span class="mord mathnormal" style="margin-right:0.07153em;">K</span></span></span></span></p>
</blockquote>
<h3 id="直接寻址">直接寻址</h3>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs asm">mov byte [offset], 0x10 ;offset为常量<br>mov word [offset], 0x10<br>mov dword [offset], 0x10<br></code></pre></td></tr></table></figure>
<h3 id="基址寻址">基址寻址</h3>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs asm">mov ax, [bx] ;段寄存器ds<br>mov ax, [bp] ;段寄存器ss<br>mov ax, [si] ;段寄存器ds<br>mov ax, [di] ;段寄存器ds<br></code></pre></td></tr></table></figure>
<h3 id="转移指令jmp">转移指令<code>jmp</code></h3>
<p>jmp short 偏移地址 （占用两个字节）-128～127<br>
jmp rear 偏移地址 （占用三个字节）-32768～32767<br>
jmp far cs:ip</p>
<blockquote>
<p>程序的指令的地址通过CS:IP获取<br>
CS为代码段的段地址，IP为偏移地址</p>
</blockquote>
<h3 id="函数和堆栈">函数和堆栈</h3>
<blockquote>
<p>访问栈数据通过SS:SP，SS为堆栈段地址，SP为栈顶指针<br>
调用函数指令call function（调用时执行了push cs; push ip）<br>
函数返回指令ret （pop ip）<br>
远返回指令retf（返回时执行了pop ip; pop cs）</p>
</blockquote>
<h3 id="实模式内存布局">实模式内存布局</h3>
<table>
<thead>
<tr>
<th>起始地址</th>
<th>结束地址</th>
<th>大小</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>0x000</td>
<td>0x3FF</td>
<td>1KB</td>
<td>中断向量表</td>
</tr>
<tr>
<td>0x400</td>
<td>0x4FF</td>
<td>256B</td>
<td>BIOS数据区</td>
</tr>
<tr>
<td>0x500</td>
<td>0x7BFF</td>
<td>29.75KB</td>
<td>可用区域</td>
</tr>
<tr>
<td>0x7C00</td>
<td>0x7DFF</td>
<td>512B</td>
<td>MBR加载区域</td>
</tr>
<tr>
<td>0x7E00</td>
<td>0x9FBFF</td>
<td>607.6KB</td>
<td>可用区域</td>
</tr>
<tr>
<td>0x9FC00</td>
<td>0x9FFFF</td>
<td>1KB</td>
<td>扩展BIOS数据区</td>
</tr>
<tr>
<td>0xA0000</td>
<td>0xAFFFF</td>
<td>64KB</td>
<td>用于彩色显示适配器</td>
</tr>
<tr>
<td>0xB0000</td>
<td>0xB7FFF</td>
<td>32KB</td>
<td>用于黑白显示适配器</td>
</tr>
<tr>
<td>0xB8000</td>
<td>0xBFFFF</td>
<td>32KB</td>
<td>用于文本显示适配器</td>
</tr>
<tr>
<td>0xC0000</td>
<td>0xC7FFF</td>
<td>32KB</td>
<td>显示适配器BIOS</td>
</tr>
<tr>
<td>0xC8000</td>
<td>0xEFFFF</td>
<td>160KB</td>
<td>映射内存</td>
</tr>
<tr>
<td>0xF0000</td>
<td>0xFFFEF</td>
<td>64KB-16B</td>
<td>系统BIOS</td>
</tr>
<tr>
<td>0xFFFF0</td>
<td>0xFFFF</td>
<td>16B</td>
<td>系统BIOS入口地址</td>
</tr>
</tbody>
</table>
<blockquote>
<p>一个中断向量使用4个字节(4B)表示，所以1KB大小的中断向量表最多可以保存256个中断<br>
0号中断（除法错误）: 除零<br>
0x80中断(128号中断): linux系统调用中断(80386, 软中断)</p>
</blockquote>
<h2 id="内存检测">内存检测</h2>
<p>BIOS 0x15 0xe820</p>
<p>Address Range Descriptor Structure ARDS</p>
<table>
<thead>
<tr>
<th style="text-align:center">字节偏移量</th>
<th>属性名称</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">0</td>
<td>BaseAddrLow</td>
<td>基地址的低32位</td>
</tr>
<tr>
<td style="text-align:center">4</td>
<td>BaseAddrHigh</td>
<td>基地址的高32位</td>
</tr>
<tr>
<td style="text-align:center">8</td>
<td>LengthLow</td>
<td>内存长度的低32位，以字节为单位</td>
</tr>
<tr>
<td style="text-align:center">12</td>
<td>LengthHigh</td>
<td>内存长度的高32位，以字节位单位</td>
</tr>
<tr>
<td style="text-align:center">16</td>
<td>Type</td>
<td>本段内存的类型</td>
</tr>
</tbody>
</table>
<h3 id="Type-字段">Type 字段</h3>
<table>
<thead>
<tr>
<th style="text-align:center">Type值</th>
<th>名称</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">1</td>
<td>AddressRangeMemory</td>
<td>这段内存可以被操作系统使用</td>
</tr>
<tr>
<td style="text-align:center">2</td>
<td>AddressRangeReserved</td>
<td>内存使用中或者被系统保留操作系统不可以使用此内存</td>
</tr>
<tr>
<td style="text-align:center">其他</td>
<td>未定义</td>
<td>未定义，将来会用到，目前保留，但是需要操作系统一样将其视为ARR（AddressRangeReserved）</td>
</tr>
</tbody>
</table>
<h2 id="保护模式和全局描述符">保护模式和全局描述符</h2>
<p><img src="/img/gdt.jpg" srcset="/img/loading.gif" lazyload alt="gdt"><br>
<img src="/img/GDT.jpg" srcset="/img/loading.gif" lazyload alt="GDT"></p>
<table>
<thead>
<tr>
<th>类型(位数)</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>Limit(0~15)</td>
<td>16位,段界限</td>
</tr>
<tr>
<td>Base(16~31)</td>
<td>16位,基地址</td>
</tr>
<tr>
<td>Base(32~39)</td>
<td>12位,基地址</td>
</tr>
<tr>
<td>Type(40~43)</td>
<td>4位,段类型</td>
</tr>
<tr>
<td>Access Rights(44~47)</td>
<td>4位,访问状态</td>
</tr>
<tr>
<td>Limit(48~51)</td>
<td>4位,段界限</td>
</tr>
<tr>
<td>AV(52)</td>
<td>1位,Available</td>
</tr>
<tr>
<td>0(53)</td>
<td>1位,64位扩展标志</td>
</tr>
<tr>
<td>D/B(54)</td>
<td>1位,32位还是16位</td>
</tr>
<tr>
<td>G(55)</td>
<td>1位,粒度4KB还是1B</td>
</tr>
<tr>
<td>Base(56~63)</td>
<td>8位,基地址</td>
</tr>
</tbody>
</table>
<p>D/B有两种：当这个段被type设置为代码段时，D=1代表这是32位的程序，D=0代表这是16位的程序；<br>
如果是向下拓展的数据段，则称为B位，B=1代表最大可访问范围是4GB，B=0代表最大可访问范围是64k，<br>
如果表示的是堆栈段，则B=1,使用esp寄存器作为栈顶寄存器，否则使用sp寄存器</p>
<p>TYPE属性存储段的类型信息，该属性的意义随着S属性不同而不同</p>
<p>S为1时(该段为数据段或代码段)</p>
<table>
<thead>
<tr>
<th>Type</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>A(40)</td>
<td>1表示被内存访问过</td>
</tr>
<tr>
<td>R/W(41)</td>
<td>读/写</td>
</tr>
<tr>
<td>C/E(42)</td>
<td>X为0时段的增长方向/X为1时表示代码的是否一致性</td>
</tr>
<tr>
<td>X(43)</td>
<td>1表示代码段/0表示数据段</td>
</tr>
</tbody>
</table>
<blockquote>
<p>一致代码段的“一致”意思是：当CPU执行jmp等指令将CS寄存器指向该代码段时，<br>
如果当前的特权级低于该代码段的特权级,那么当前的特权级会被延续下去(简单的说就是可以被低特权级的用户直接访问的代码)<br>
如果当前的特权级高于该代码段的特权级,那么会触发常规保护错误(可以理解为内核态下不允许直接执行用户态的代码)<br>
如果不是一致代码段并且该代码段的特权级不等于（高于和低于都不行）当前的特权级，那么会引发常规保护错误</p>
</blockquote>
<p>S为0时(该段为系统段)</p>
<table>
<thead>
<tr>
<th>TYPE的值（16进制）</th>
<th>TYPE的值(二进制)</th>
<th>解释</th>
</tr>
</thead>
<tbody>
<tr>
<td>0x1</td>
<td>0 0 0 1</td>
<td>可用286TSS</td>
</tr>
<tr>
<td>0x2</td>
<td>0 0 1 0</td>
<td>该段存储了局部描述符表（LDT）</td>
</tr>
<tr>
<td>0x3</td>
<td>0 0 1 1</td>
<td>忙的286TSS</td>
</tr>
<tr>
<td>0x4</td>
<td>0 1 0 0</td>
<td>286调用门</td>
</tr>
<tr>
<td>0x5</td>
<td>0 1 0 1</td>
<td>任务门</td>
</tr>
<tr>
<td>0x6</td>
<td>0 1 1 0</td>
<td>286中断门</td>
</tr>
<tr>
<td>0x7</td>
<td>0 1 1 1</td>
<td>286陷阱门</td>
</tr>
<tr>
<td>0x9</td>
<td>1 0 0 1</td>
<td>可用386TSS</td>
</tr>
<tr>
<td>0xB</td>
<td>1 0 1 1</td>
<td>忙的386TSS</td>
</tr>
<tr>
<td>0xC</td>
<td>1 1 0 0</td>
<td>386调用门</td>
</tr>
<tr>
<td>0xE</td>
<td>1 1 1 0</td>
<td>386中断门</td>
</tr>
<tr>
<td>0xF</td>
<td>1 1 1 1</td>
<td>386陷阱门</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Access Rights(位)</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>44</td>
<td>S位:1表示代码段或数据段/0表示系统段</td>
</tr>
<tr>
<td>45~46</td>
<td>DPL(Descriptor Privilege Level),描述符特权级</td>
</tr>
<tr>
<td>47</td>
<td>P位:1表示在内存中/0表示在磁盘中</td>
</tr>
</tbody>
</table>
<ul>
<li>全局描述符最多有8192个(段选择子用于表示段个数的位数是13,<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mn>2</mn><mn>13</mn></msup><mo>=</mo><mn>8192</mn></mrow><annotation encoding="application/x-tex">2^{13} = 8192</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8141em;"></span><span class="mord"><span class="mord">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">13</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">8192</span></span></span></span>)</li>
<li>每个描述符使用8个字节（64位）来描述</li>
<li>第一个描述符必须是0(NULL描述符)</li>
</ul>
<p><img src="/img/descriptor.jpg" srcset="/img/loading.gif" lazyload alt="descriptor"></p>
<h2 id="段选择子">段选择子</h2>
<ul>
<li>16位</li>
</ul>
<table>
<thead>
<tr>
<th>位</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>0~1</td>
<td>RPL,请求特权级</td>
</tr>
<tr>
<td>2</td>
<td>TI,0表示访问的是全局描述符表，1表示访问的是局部描述符表</td>
</tr>
<tr>
<td>3~15</td>
<td>全局描述符索引</td>
</tr>
</tbody>
</table>
<h2 id="启动保护模式">启动保护模式</h2>
<ul>
<li>将cr0寄存器第0位置1</li>
<li>跳转指令跳转到保护模式下的代码继续执行,会清空流水线</li>
</ul>
<h2 id="基础显卡驱动">基础显卡驱动</h2>
<h3 id="显卡模式">显卡模式</h3>
<ul>
<li>CGA (Color Graphics Adapter)
<ul>
<li>图形模式
<ul>
<li>160 * 100</li>
<li>320 * 240</li>
<li>640 * 200</li>
</ul>
</li>
<li>文本模式
<ul>
<li>40 * 25</li>
<li>80 * 25</li>
</ul>
</li>
</ul>
</li>
<li>EGA (Enhanced Graphics Adapter)</li>
<li>MCGA (Multi Color Graphics Array)</li>
</ul>
<h3 id="CRTC-Cathode-Ray-Tube-Controller">CRTC (Cathode Ray Tube Controller)</h3>
<p>CGA 使用的MC6845芯片</p>
<p>端口号: CPU外部设备寄存器编号</p>
<ul>
<li>CRT 地址寄存器 3d4</li>
<li>CRT 数据寄存器 3d5</li>
<li>CRT 光标位置(高位0xe/低位0xf)</li>
<li>CRT 显示开始位置(高位0xc/低位0xd)</li>
</ul>
<h3 id="控制字符">控制字符</h3>
<p>控制字符是指ASCII码表开头的32个字符(0x00~0x1f)以及DEL(0x7f)</p>
<p><img src="/img/ascii-ctl.png" srcset="/img/loading.gif" lazyload alt=""></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E6%96%87%E6%A1%A3/" class="category-chain-item">文档</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/8086/" class="print-no-link">#8086</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>8086处理器</div>
      <div>https://lingllqs.github.io/archives/7d86c998.html</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>lingllqs</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年12月5日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/" rel="external nofollow noreferrer">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/archives/78e48626.html" title="九九乘法表">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">九九乘法表</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/archives/2f57a694.html" title="正则表达式">
                        <span class="hidden-mobile">正则表达式</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"ZtaCuooNxUcOqZ44oEeRZvpa-gzGzoHsz","appKey":"ZQm92JiXmMQqpk6hi7Zqoi0w","path":"window.location.pathname","placeholder":null,"avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":true,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":true},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  


  
  









    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  
      <script>
        if (!window.MathJax) {
          window.MathJax = {
            tex    : {
              inlineMath: { '[+]': [['$', '$']] }
            },
            loader : {
              load: ['ui/lazy']
            },
            options: {
              renderActions: {
                insertedScript: [200, () => {
                  document.querySelectorAll('mjx-container').forEach(node => {
                    let target = node.parentNode;
                    if (target.nodeName.toLowerCase() === 'li') {
                      target.parentNode.classList.add('has-jax');
                    }
                  });
                }, '', false]
              }
            }
          };
        } else {
          MathJax.startup.document.state(0);
          MathJax.texReset();
          MathJax.typeset();
          MathJax.typesetPromise();
        }

        Fluid.events.registerRefreshCallback(function() {
          if ('MathJax' in window && MathJax.startup.document && typeof MathJax.startup.document.state === 'function') {
            MathJax.startup.document.state(0);
            MathJax.texReset();
            MathJax.typeset();
            MathJax.typesetPromise();
          }
        });
      </script>
    

  <script  src="https://lib.baomitu.com/mathjax/3.2.2/es5/tex-mml-chtml.js" ></script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
